

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:keep_account/bean/user.dart';
import 'package:keep_account/bean/work_records.dart';
import 'package:keep_account/dio/DefaultRequestResult.dart';
import 'package:keep_account/dio/http_request.dart';
import 'package:keep_account/utils/datetime_utils.dart';
import 'package:keep_account/vm/base_controller.dart';

class AddWorkRecordsController extends BaseController {

  var productQuantityController = TextEditingController();
  var productPriceController = TextEditingController();
  var teamSizeController = TextEditingController();

  var workDate = "".obs;

  @override
  void onReady() {
    super.onReady();
    workDate.value = "${getCurrentYear()}-${getCurrentMonth().toString().padLeft(2,"0")}-${getCurrentDay().toString().padLeft(2,"0")}";

  }

  void submitWorkRecord(){
    if (productQuantityController.value.text.isEmpty) {
      EasyLoading.showError("请输入数量");
      return;
    }
    if (productPriceController.value.text.isEmpty) {
      EasyLoading.showError("请输入单价");
      return;
    }
    if (teamSizeController.value.text.isEmpty) {
      EasyLoading.showError("请输入团队人数");
      return;
    }
    HttpRequest().addWorkRecords(
      {
        "teamSize" : teamSizeController.value.text,
        "workDate" : workDate.value,
        "productPrice" : productPriceController.value.text,
        "productQuantity" : productQuantityController.value.text,
      },
      requestResult: BoolRequestResult(
          success: (){
            EasyLoading.showSuccess("提交成功");
          }, 
          error: (error){
            EasyLoading.showError(error.message);
          })
    );
  }

  @override
  void retry() {

  }

}